//改变tr背景色
function changblockcolor(tr, color) {
	tr.style.backgroundColor = color;
}
//还原tr背景色		
function blackblockcolor(tr, color) {
	tr.style.backgroundColor = color;
}
//多选框全选
function sltall(checkstatus) {
	var objs = document.getElementsByTagName("input");
	var d = document.all; //如果在form里(如form1)则d=document.form1
	var i;
	for (var i = 0; i < objs.length; i++) {
		if (objs[i].type == "checkbox" && objs[i].name != "checkall") {
			objs[i].checked = checkstatus;
		}
	}
}


	//修改收到邮件的读写状态
	   function updateemailstart(start)
	   {
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
		  	if(check[i].checked == true)
			{
				array[i] = check[i].value;	
			}
	   	  	
	   	  }
	   	  tjsemailReceivedBo.updateTjsmailReceivedStartList(array,start,updateemailstartafter)
	   	  var  hidden   = document.getElementById('start');
	   	  hidden.value = start;
	   }
	   //修改邮件的读写状态的回调函数
	   
	   function updateemailstartafter()
	   {
	   		  var check =	 document.getElementsByName('checkbox2');
	   	  	   for(var i = 0;i<check.length;i++)
	   	  		{
					if(check[i].checked == true)
					{
						
					var td =  document.getElementById(check[i].value)
	   	  			var img = td.firstChild;
	   	  			if(document.getElementById('start').value == 1)
	   	  			{
	   	  				img.setAttribute("src","images/m_icon23.gif");	
	   	  				img.style.display= 'inline';
	   	  			}
	   	  			else 
	   	  			{
	   	  				img.style.display= 'none';
	   	  			}	
					}
	   	  			
	   	  		}
	   }
	   //修改收到邮件的优先级
	   function updateemailtype(type)
	   {
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
		  	if(check[i].checked == true)
			{
				array[i] = check[i].value;	
			}
	   	  // 	array[i] = check[i].value;
	   	  }
	   	  tjsemailReceivedBo.updateTjsmailReceivedType(array,type,updateemailtypeafter)
	   	  var  hidden   = document.getElementById('type');
	   	  hidden.value = type;
	   }
	   //修改邮件的优先级回调
	   function updateemailtypeafter()
	   {
	   		   var check =	 document.getElementsByName('checkbox2');
	   	  	   for(var i = 0;i<check.length;i++)
	   	  		{
					if (check[i].checked == true) {
					
					
						var td = document.getElementById(check[i].value)
						var img = td.childNodes[1];
						if (document.getElementById('type').value == 1) {
							img.setAttribute("src", "images/t.gif");
							img.style.display = 'inline';
							
						}
						else 
							if (document.getElementById('type').value == 2) {
								img.setAttribute("src", "images/b.gif");
								img.style.display = 'inline';
								
							}
							else {
								img.style.display = 'none';
							}
					}
	   	  		}
	   }
	   //修改收到邮件的标签
	   function updateemailtag(tag)
	   {
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
		  	if(check[i].checked == true)
			{
				array[i] = check[i].value;	
			}
	   	  	
	   	  	// array[i] = check[i].value;
	   	  }
	   	  tjsemailReceivedBo.updateTjsmailReceivedTagList(array,tag,updateemailtagafter)
	   	  var  hidden   = document.getElementById('tag');
	   	  hidden.value = tag;
	   }
	   //修改邮件的标签回调
	   function updateemailtagafter()
	   {
	   			
	   		   var check =	 document.getElementsByName('checkbox2');
	   	  	   for(var i = 0;i<check.length;i++)
	   	  		{
					
						if (check[i].checked == true)
						 {
	
							var td = document.getElementById(check[i].value)
							var img = td.childNodes[2];
							// alert(td.childNodes.length);
							// alert(img);
							if (document.getElementById('tag').value == 1) {
								img.setAttribute("src", "images/mail_01.gif");
								img.style.display = 'inline';
								
							}
							else 
								if (document.getElementById('tag').value == 2) {
									img.setAttribute("src", "images/mail_02.gif");
									img.style.display = 'inline';
								}
								else 
									if (document.getElementById('tag').value == 3) {
										img.setAttribute("src", "images/mail_03.gif");
										img.style.display = 'inline';
									}
									else 
										if (document.getElementById('tag').value == 4) {
											img.setAttribute("src", "images/mail_04.gif");
											img.style.display = 'inline';
										}
										else 
											if (document.getElementById('tag').value == 5) {
												img.setAttribute("src", "images/mail_05.gif");
												img.style.display = 'inline';
											}
											else {
												img.style.display = 'none';
											}
						}
	   	  		}
	   }
	   

	  //修改草稿的读写状态
	   function updateDraftstart(start)
	   {
	   	  
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
		  	if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  	
	   	  }
	   	  tjsDraftBo.updateDraftStart(array,start,updateemailstartafter)
	   	  var  hidden   = document.getElementById('start');
	   	  hidden.value = start;
	   }
	   //修改草稿的优先级
	   function updateDrafttype(type)
	   {
	   	  
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
		  	
	   	   	if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
	   	  tjsDraftBo.updateDraftType(array,type,updateemailtypeafter)
	   	  var  hidden   = document.getElementById('type');
	   	  hidden.value = type;
	   }
	   
	   //修改草稿的标签
	   function updateDraftag(tag)
	   {
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
	   	  	 	if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
	   	  tjsDraftBo.updateDraftTag(array,tag,updateemailtagafter)
	   	  var  hidden   = document.getElementById('tag');
	   	  hidden.value = tag;
	   } 
	   	   
  		//修改删除邮件的读写状态
	   function updateDeletetstart(start)
	   {
	   	  
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
	   	  	 	if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
	   	  tjsDeleteEmailBo.updateDeleteMailStart(array,start,updateemailstartafter)
	   	  var  hidden   = document.getElementById('start');
	   	  hidden.value = start;
	   }
	   //修改删除邮件的优先级
	   function updateDeletetype(type)
	   {
	   	  
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
	   	   	if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
	   	  tjsDeleteEmailBo.updateDeleteMailType(array,type,updateemailtypeafter)
	   	  var  hidden   = document.getElementById('type');
	   	  hidden.value = type;
	   }
	   
	   //修改删除邮件的标签
	   function updateDeletetag(tag)
	   {
	   	  var check =	 document.getElementsByName('checkbox2');
		
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
		  
	   	  	 	if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
		
	   	  tjsDeleteEmailBo.updateDeleteMailTag(array,tag,updateemailtagafter)
	   	  var  hidden   = document.getElementById('tag');
	   	  hidden.value = tag;
	   }
	   
	  //修改发送邮件的读写状态
	   function updateSendtstart(start)
	   {
	   	  
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
	   	  	 	if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
	   	  tjsmailBo.updateTjsmailStart(array,start,updateemailstartafter)
	   	  var  hidden   = document.getElementById('start');
	   	  hidden.value = start;
	   }
	   
	   //修改发送邮件的优先级
	   function updateSendtype(type)
	   {
	   	  
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
	   	  	 	if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
	   	  tjsmailBo.updateTjsmailType(array,type,updateemailtypeafter)
	   	  var  hidden   = document.getElementById('type');
	   	  hidden.value = type;
	   } 
	   
	    //修改发送邮件的标签
	   function updateSendtag(tag)
	   {
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
	   	  	 	if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
	   	  tjsmailBo.updateTjsmailTag(array,tag,updateemailtagafter)
	   	  var  hidden   = document.getElementById('tag');
	   	  hidden.value = tag;
	   }
	   
	   //删除邮件
	   function deleteRecivedmail()
	   {
	   		  var check =	 document.getElementsByName('checkbox2');
	   		  for(var i =0;i< check.length;i++)
	   		  {
	   		  	if(check[i].checked == true)
	   		  	{
	   		  		document.form1.submit();
					 return;
	   		  	}
	   		  	else if( i+1 == check.length)
	   		  	{
	   		  	document.getElementById('black_over').style.display = "block";
				document.getElementById('deletefrom').style.top =  document.body.clientHeight/2;
				document.getElementById('deletefrom').style.left = document.body.clientWidth/5;
				document.getElementById('deletefrom').style.display = "block";
				return;	
	   		  	}
	   		  }
	   		
	   }
	   //取消显示的层
	   	function qxdeletefrom()
	{
		document.getElementById('black_over').style.display = "none";
		document.getElementById('deletefrom').style.display = "none";
	}
	//取消显示的层
	function quxiao(id)
	{
		document.getElementById('black_over').style.display = "none";
		document.getElementById(id).style.display = "none";
	}
	//添加文件夹
	function addfold(){
		var foldname = document.getElementById('foldname').value;
		var userid = document.getElementById('userid').value;
		if (foldname.length >4) {
			alert('文件夹名称不得超过4个字符');
			return;
			
		}
		if (foldname.replace(/(^\s*)/g, "")== '') {
			alert('请输入文件夹名称');
			return;
			
		}
		tjsEmailFolderBo.addTjsEmailFold(foldname, userid, addfoldafter);
	}
	
	//添加文件夹回调
	function addfoldafter(data)
	{
		var li = document.createElement('li');
		li.className = 'l_05';
		var foldname = document.getElementById('foldname').value;
		var text = document.createTextNode(foldname);
		var ul = document.getElementById('filelist');
		var link = document.createElement('a');
		var basepath = document.getElementById('basepath').value;
		link.setAttribute("href", basepath+'tjsinfo/tjsoa/mail/deleteEmaiList.do?id='+data);
		link.appendChild(text);
		li.appendChild(link);
		ul.appendChild(li);
		quxiao('addfoldform');
	}
	//弹出层JS函数
	function addFoldFrom(id)
	{
			var userid   = document.getElementById('userid').value;
			var documentfoldinput = document.getElementById('foldname');
			documentfoldinput.value = '';
			if(tjsEmailFolderBo.selectByUserId(userid,autofolder))
			{
							
			}
			
	}
	//添加文件夹弹出层验证JS函数
	function autofolder(data)
	{
		if(data.length == 3)
		{
			alert('每人最多3个文件夹');
			return false;
		}
		else
		{
			document.getElementById('black_over').style.display = "block";
		document.getElementById('addfoldform').style.top =  document.body.clientHeight/2;
		document.getElementById('addfoldform').style.left = document.body.clientWidth/5;
		document.getElementById('addfoldform').style.display = "block";
		}
		return true;
	}
	//查询用户的文件夹
	function selectFoldFrom()
	{
		var userid   = document.getElementById('userid').value;
		tjsEmailFolderBo.selectByUserId(userid,selectFoldFromafter);
	}
	//查询用户的文件夹2
	function selectFoldFrom2()
	{
		var userid   = document.getElementById('userid').value;
		tjsEmailFolderBo.selectByUserId(userid,selectFoldFromafter2);
	}
	//弹出选择文件夹层
	function selectFoldFromafter(data)
	{
		
		if(data.length > 0)
		{
		document.getElementById('black_over').style.display = "block";
		document.getElementById('foldlist').style.top =  document.body.clientHeight/2;
		document.getElementById('foldlist').style.left = document.body.clientWidth/5;
		document.getElementById('foldlist').style.display = "block";
		// 	addFoldFrom('foldlist');
		
			
			var tad = document.getElementById('foldtd');
			var arraychile = tad.childNodes;
		
			var line = arraychile.length;
			for(var chile = 0;chile<line;chile++) 
			{
				
				tad.removeChild(tad.firstChild); 
			}
			for(var i = 0;i<data.length;i++)
			{
			
			var fold = data[i];
			var td = document.getElementById('foldtd');
			
			var radio = document.createElement("<input name='flodname'>");
			radio.setAttribute('type','radio');
			//radio.setAttribute('name','foldname');
			radio.setAttribute('value',fold.folderId);
			// alert(fold.folderName);
			var text =  document.createTextNode(fold.folderName);
			//radio.appendChild(text);
			// var br = document.createElement("br");
			
			td.appendChild(radio);
			td.appendChild(text);
			// td.appendChild(br);
			
			}	
		}
		else
		{
			alert('没有文件夹可以选择!');
		}	
		
	}
	
	//弹出选择文件夹层
	function selectFoldFromafter2(data)
	{
		
		if(data.length > 0)
		{
		document.getElementById('black_over').style.display = "block";
		document.getElementById('foldlist2').style.top =  document.body.clientHeight/2;
		document.getElementById('foldlist2').style.left = document.body.clientWidth/5;
		document.getElementById('foldlist2').style.display = "block";
		// 	addFoldFrom('foldlist');
		
			
			var tad = document.getElementById('foldtd2');
			var arraychile = tad.childNodes;
		
			var line = arraychile.length;
			for(var chile = 0;chile<line;chile++) 
			{
				
				tad.removeChild(tad.firstChild); 
			}
			for(var i = 0;i<data.length;i++)
			{
			
			var fold = data[i];
			var td = document.getElementById('foldtd2');
			
			var radio = document.createElement("<input name='flodname'>");
			radio.setAttribute('type','radio');
			//radio.setAttribute('name','foldname');
			radio.setAttribute('value',fold.folderId);
			// alert(fold.folderName);
			var text =  document.createTextNode(fold.folderName);
			//radio.appendChild(text);
			// var br = document.createElement("br");
			
			td.appendChild(radio);
			td.appendChild(text);
			// td.appendChild(br);
			
			}	
		}
		else
		{
			alert('没有文件夹可以选择!');
		}	
		
	}
	
	
	
		//修改文件夹型邮件的读写状态
	   function updatefoldemailstart(start)
	   {
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
		  	if(check[i].checked == true)
			{
				array[i] = check[i].value;	
			}
	   	  	
	   	  }
		  var  hidden   = document.getElementById('start');
	   	  hidden.value = start;
	   	  tjsFoldMailBo.updateReadList(array,start,updateemailstartafter);
	   	
	   }
	   
	    //修改发送邮件的优先级
	   function updateFoldmailtype(type)
	   {
	   	  
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
	   	  	 if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
	   	  tjsFoldMailBo.updateTypeList(array,type,updateemailtypeafter)
	   	  var  hidden   = document.getElementById('type');
	   	  hidden.value = type;
	   } 
	
	   
	   
	   //修改文件夹邮件的标签
	   function updateFloadEmailtag(tag)
	   {
	   	  var check =	 document.getElementsByName('checkbox2');
	   	  var array = new Array();
	   	  for(var i = 0;i<check.length;i++)
	   	  {
	   	  	 if(check[i].checked == true)
			{
				array[i] = check[i].value;
			}
	   	  }
	   	  tjsFoldMailBo.updateTagList(array,tag,updateemailtagafter)
	   	  var  hidden   = document.getElementById('tag');
	   	  hidden.value = tag;
	   }
	   //后退
	   function back()
	   {
	   		history.back(-1);
	   }
	   //刷新页面
	function reload()
	{
		location.reload();	
	}
	

	
	//判断IE版本
function ieverson()
{
window["MzBrowser"]={};(function()
{
  if(MzBrowser.platform) return;
  var ua = window.navigator.userAgent;
  MzBrowser.platform = window.navigator.platform;

  MzBrowser.firefox = ua.indexOf("Firefox")>0;
  MzBrowser.opera = typeof(window.opera)=="object";
  MzBrowser.ie = !MzBrowser.opera && ua.indexOf("MSIE")>0;
  MzBrowser.mozilla = window.navigator.product == "Gecko";
  MzBrowser.netscape= window.navigator.vendor=="Netscape";
  MzBrowser.safari  = ua.indexOf("Safari")>-1;

  if(MzBrowser.firefox) var re = /Firefox(\s|\/)(\d+(\.\d+)?)/;
  else if(MzBrowser.ie) var re = /MSIE( )(\d+(\.\d+)?)/;
  else if(MzBrowser.opera) var re = /Opera(\s|\/)(\d+(\.\d+)?)/;
  else if(MzBrowser.netscape) var re = /Netscape(\s|\/)(\d+(\.\d+)?)/;
  else if(MzBrowser.safari) var re = /Version(\/)(\d+(\.\d+)?)/;
  else if(MzBrowser.mozilla) var re = /rv(\:)(\d+(\.\d+)?)/;

  if("undefined"!=typeof(re)&&re.test(ua))
    MzBrowser.version = parseFloat(RegExp.$2);
})(); 

// alert(MzBrowser.ie);//是否ie
// alert(MzBrowser.firefox);
// alert(MzBrowser.version);//版本
if (MzBrowser.ie == true && MzBrowser.version == 7) {
	var rightdiv = document.getElementById('rightindex');
	rightdiv.style.height="97%";
	var mail_left = document.getElementById('mail_left');
	mail_left.style.height="90%";
}
else 
	if (MzBrowser.ie == true && MzBrowser.version == 6) {
		
		var rightdiv = document.getElementById('rightindex');
	rightdiv.style.height="90%";
	var mail_left = document.getElementById('mail_left');
	mail_left.style.height="90%";
	}
	if(screen.width >1024)
	{
		document.getElementById('mail_title').style.paddingLeft='210px';
	}
	
}